package j01file;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

public class J1file {
    public static void main(String[] args) {
        // 绝对路径 ，不推荐
        File file = new File("C:\\Users\\Administrator\\Desktop\\short-learn\\java-learn\\_1218\\src\\j01file\\1.txt");
        File file2 = new File("C:\\Users\\Administrator\\Desktop\\short-learn\\java-learn\\_1218\\src\\j01file\\2.txt");

        System.out.println(file.exists());//true
        System.out.println(file2.exists());//false


        //相对路径
        File file12 = new File("_1218\\src\\j01file\\1.txt");
        System.out.println("file12.exists() = " + file12.exists());

        File file3 = new File("_1218","src\\j01file\\1.txt");
        System.out.println("file3.exists() = " + file3.exists());
        //文件夹
        File file4 = new File("_1218\\src\\j01file");
        System.out.println("file4.exists() = " + file4.exists());

        File file5 = new File(file4,"1.txt");
        System.out.println("file5.exists() = " + file5.exists());
    }
}

class J2methods{
    public static void main(String[] args) throws Exception {
        File file1 = new File("_1218/src/j01file/hlm.txt");
//        System.out.println("file1.createNewFile() = " + file1.createNewFile());

//        file1.delete();
        System.out.println(file1.getAbsoluteFile());
        System.out.println(file1.getName());
        System.out.println(file1.getParent());

        //必须要有这个文件
        System.out.println("file1.isFile() = " + file1.isFile());//true
        System.out.println("file1.isDirectory() = " + file1.isDirectory());//false

        System.out.println(file1.lastModified());
    }
}
class J3methods2{
    public static void main(String[] args) {
        //txt 1字母，2个字节
        File file = new File("_1218/src/j01file/1.txt");
        System.out.println("file.length() = " + file.length());

        File folder = new File("_1218/src/j01file");
        File[] fileArr = folder.listFiles();
        System.out.println("fileArr = " + fileArr);
        System.out.println(Arrays.toString(fileArr));
        System.out.println("=====");
//        File folder2 = new File("_1218/src/j01file/aa");
        File folder2 = new File("_1218/src/j01file/cc/dd");
//        System.out.println("folder2.mkdir() = " + folder2.mkdir());
        System.out.println("folder2.mkdirs() = " + folder2.mkdirs());
        System.out.println("<<<<<<<");
        new File("_1218/src/j01file/1.txt").renameTo(
                new File("_1218/src/j01file/aa/1copy.txt")
        );
    }
}